#include "onetwo.h"
#include "bubu.h"

//一二基类的构造函数
Onetwo::Onetwo()
{
    movie = nullptr;
    atk = counter = state = time = 0;
}

Onetwo::~Onetwo()
{
    delete movie;
}


//返回边界矩形坐标数值
QRectF Onetwo::boundingRect() const
{
    return QRectF(-50, -50, 100, 100);
}

//绘制一二
void Onetwo::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option)
    Q_UNUSED(widget)
    painter->drawImage(boundingRect(), movie->currentImage());
}

//判断是否发生碰撞,如果碰撞，布布进攻一二
bool Onetwo::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const
{
    Q_UNUSED(mode)
    //左右30像素内是否存在布布
    return other->type() == Bubu::Type && qFuzzyCompare(other->y(), y()) && qAbs(other->x() - x()) < 30;
}

int Onetwo::type() const
{
    return Type;
}

//设置一二动图
void Onetwo::setMovie(QString path)
{
    if (movie)
        delete movie;
    movie = new QMovie(path);
    movie->start();
}
